//
//  ZSTabBar.m
//  微博-0C
//
//  Created by 周李波 on 16/7/19.
//  Copyright © 2016年 q. All rights reserved.
//

#import "ZSTabBar.h"
#import <Masonry.h>



@interface ZSTabBar ()



@property (nonatomic,weak)UIButton *composeButton;

@end

@implementation ZSTabBar

#pragma mark
#pragma mark - 按钮点击
- (void)composeButtonClick{
    if (self.composeBlock) {
        self.composeBlock();
    }
    
}
#pragma mark
#pragma mark - 初始化方法
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
        
    }
    
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    [self setupLayout];
}

#pragma mark
#pragma mark - 设置UI
- (void)setupUI{
    UIButton *composeButton = [[UIButton alloc]init];
    [composeButton setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [composeButton setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
    [composeButton setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [composeButton setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
    [composeButton addTarget:self action:@selector(composeButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [composeButton sizeToFit];
    [self addSubview:composeButton];
    
    self.composeButton = composeButton;
    
}

#pragma mark
#pragma mark - 设置约束
- (void)setupLayout{
    __block int index = 0;
    
    
    CGFloat width = self.frame.size.width * 0.2;
    [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            obj.frame  = CGRectMake((index * width), obj.frame.origin.y, width, obj.frame.size.height);
            index++;
            if (index == 2) {
                index++;
            }
            
            
        }
        
        
    }];
    
    self.composeButton.center = CGPointMake(self.frame.size.width*0.5, self.frame.size.height*0.5);
    
}


@end
